#include "../head/client.h"
#include "../head/command.h"

int transmit(int netfd,int type,int len,char *buf){
    TLVMsg msg;
    msg.type=type;
    msg.value_len=len;
    if(buf==NULL){
        send(netfd,&msg.type,sizeof(msg.type),0);
        send(netfd,&msg.value_len,sizeof(msg.value_len),0);   
        send(netfd,buf,(msg.value_len),0);   
    }else{
        strncpy(msg.value,buf, MAX_DETAIL_LEN);
        send(netfd,&msg.type,sizeof(msg.type),0);
        send(netfd,&msg.value_len,sizeof(msg.value_len),0);   
        send(netfd,msg.value,(msg.value_len),0);   

    }
    return 0;
}

int recvfd(int netfd,TLVMsg *msg){
    recv(netfd,&msg->type,sizeof(int),0);
    recv(netfd,&msg->value_len,sizeof(int),0);
    recv(netfd,&msg->value,msg->value_len,0);
    return 0;
}
